package com.macro.mall.product.util;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Slf4j
public class TaskUtils {

    public static final String DEFAULT_FORMAT_YYYY_MM_DD = "yyyy-MM-dd";

    /**
     * 获取增加天数以后的日期
     * */
    public  static String getDateAddDays(int days) {
        try {
            Calendar date = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_FORMAT_YYYY_MM_DD);
            date.add(Calendar.DAY_OF_MONTH, days);
            return dateFormat.format(date.getTime());
        } catch (Exception e) {
            log.error("获取增加天数以后的日期报错：",e);
            return null;
        }
    }
    /**
     * 根据年月日返回星期几
     * @param year //年份
     * @param month //月份
     * @param day   //天
     * @return String //返回值直接返回星期几
     */
    public static String weekByDate (int year,int month,int day)
    {
        String str="";
        SimpleDateFormat fmt = new SimpleDateFormat("dd MM yyyy");

        Date d = null;
        try {
            d = fmt.parse(day+" "+month+" "+year);
        }catch (ParseException e)         {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }

        Calendar cal = Calendar.getInstance();

        cal.setTime(d);

        int weekDay = cal.get(Calendar.DAY_OF_WEEK);

        switch(weekDay) {
            case 1 : str="周日"; break;
            case 2 : str="周一"; break;
            case 3 : str="周二"; break;
            case 4 : str="周三"; break;
            case 5 : str="周四"; break;
            case 6 : str="周五"; break;
            case 7 : str="周六"; break;
            default: break;
        }
        return str;
    }
}


